package test_gui02;

import javax.swing.*;

import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.BevelBorder;
 

public class ClockTest extends JFrame {
	
  public ClockTest( )
  {
    super("Timer Demo");
    setSize(300, 100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    ClockLabel clock = new ClockLabel( );
    getContentPane( ).add(clock, BorderLayout.NORTH);
    
    setLayout(new BorderLayout());
    setSize(500, 500);
/*    
    JPanel statusPanel = new JPanel();
    statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    add(statusPanel, BorderLayout.SOUTH);
    statusPanel.setPreferredSize(new Dimension(getWidth(), 16));
    statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
    
	SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" );
    JLabel statusLabel = new JLabel(sdf.format( new GregorianCalendar().getTime() ));
    
    statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
    statusPanel.add(statusLabel);
*/ 
 /*
    // create the status bar panel and shove it down the bottom of the frame
    JPanel statusPanel = new JPanel();
    statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    frame.add(statusPanel, BorderLayout.SOUTH);
    statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 16));
    statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
    
    JLabel statusLabel = new JLabel(sdf.format( new GregorianCalendar().getTime() ));
    
    statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
    statusPanel.add(statusLabel);

    frame.setVisible(true);*/
    
  }
 
	  public static void main(String args[]) 
	  {
	    ClockTest ct = new ClockTest( );
	    ct.setVisible(true);
	  }
}

 
class ClockLabel extends JLabel implements ActionListener
{
	  public ClockLabel() 
	  {
		  
	    super("" + new Date( ));
		  
		//  SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" );
		//  String hhh =  sdf.format( new GregorianCalendar().getTime() ) ;
		 // setText(hhh);

	    Timer t = new Timer(1000, this);
	    t.start( );
	  }
	  
	  public void actionPerformed(ActionEvent ae) 
	  {
		  SimpleDateFormat sdf = new SimpleDateFormat( "dd MMM yyyy hh:mm:ss" );
		  String hhh =  sdf.format( new GregorianCalendar().getTime() ) ;
		  setText((new Date( )).toString( ));
		  setText("hhh");
	  }
}